<template>
  <div class="app-container calendar-list-container">
    <div class="filter-container">
      <el-input v-model="listQuery.company_name" placeholder="企业名称" style="width:300px"></el-input>
      <span class="search-title">注册时间&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
      <el-date-picker
        v-model="regTime"
        type="datetimerange"
        format="yyyy-MM-dd HH:mm"
        placeholder="选择日期时间"
        range-separator="至"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
        :editable="false"
        :change="changeAttr(1)"
        :picker-options="pickerOptions">
      </el-date-picker>
    </div>
    <div class="filter-container">
      <el-input v-model="listQuery.phone" placeholder="手机号" style="width:300px"></el-input>
      <span class="search-title">最后访问时间</span>
      <el-date-picker
        v-model="lastTime"
        type="datetimerange"
        format="yyyy-MM-dd HH:mm"
        placeholder="选择日期时间"
        range-separator="至"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
        :editable="false"
        :change="changeAttr(2)"
        :picker-options="pickerOptions">
      </el-date-picker>
      <el-button class="filter-item" @click="getList" type="primary" icon="el-icon-search">筛选</el-button>
    </div>
    <div style="clear:both"></div>
    <div class="filter-container">
      <component :is="wxqyList" :list="list" :listLoading="listLoading"></component>
    </div>
    <div v-show="!listLoading" class="pagination-container">
      <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page.sync="listQuery.page"
        :page-sizes="[5,10,20,30, 50]" :page-size="listQuery['per-page']" layout="total, sizes, prev, pager, next, jumper" :total="total">
      </el-pagination>
    </div>
  </div>
</template>
<style scoped>
  .el-time-spinner__wrapper {
    vertical-align: inherit;
  }
  .filter-container .filter-item {
    margin-bottom: 4px;
    margin-left: 10px;
  }
</style>
<script>
import { fetchList } from '@/api/company'
import waves from '@/directive/waves' // 水波纹指令
import wxqylist from './components/wxqylist' // 列表页

export default {
  name: 'complexTable',
  directives: {
    waves
  },
  data() {
    return {
      wxqyList: wxqylist,
      tableKey: 0,
      list: null,
      total: null,
      listLoading: true,
      listQuery: {
        page: 1,
        'per-page': 10,
        register_time_begin: '',
        register_time_end: '',
        last_access_time_begin: '',
        last_access_time_end: '',
        company_name: '',
        phone: ''
      },
      regTime: '',
      lastTime: '',
      status: '',
      pickerOptions: {
        disabledDate(time) {
          var d = new Date('2016-12-31')
          return time.getTime() > Date.now() || time.getTime() < d.getTime()
        }
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      this.listLoading = true
      fetchList(this.listQuery).then(response => {
        this.list = response.data.data
        this.total = response.data._meta.totalCount
        this.listLoading = false
      })
    },
    handleClick() {
      this.resetTemp()
      this.getList()
    },
    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },
    handleSizeChange(val) {
      this.listQuery['per-page'] = val
      this.getList()
    },
    handleCurrentChange(val) {
      this.listQuery.page = val
      this.getList()
    },
    handleModifyStatus(row, status) {
      this.$message({
        message: '操作成功',
        type: 'success'
      })
      row.status = status
    },
    // 修改日期选择器时间
    changeAttr(id) {
      if (id === 1) {
        if (this.regTime !== null) {
          this.listQuery.register_time_begin = this.regTime[0]
          this.listQuery.register_time_end = this.regTime[1]
        } else {
          this.listQuery.register_time_begin = ''
          this.listQuery.register_time_end = ''
        }
      } else if (id === 2) {
        if (this.lastTime !== null) {
          this.listQuery.last_access_time_begin = this.lastTime[0]
          this.listQuery.last_access_time_end = this.lastTime[1]
        } else {
          this.listQuery.last_access_time_begin = ''
          this.listQuery.last_access_time_end = ''
        }
      }
    },
    handleCreate() {

    },
    resetTemp() {
      this.temp = {
        id: undefined,
        importance: 1,
        remark: '',
        timestamp: new Date(),
        title: '',
        status: 'published',
        type: ''
      }
      this.listQuery = {
        page: 1,
        'per-page': 10,
        check_time_begin: '',
        check_time_end: '',
        check_result: 0
      }
      this.checkTime = ''
    }
  }
}
</script>
